import { defHttp } from '@/utils/http/axios';
import type {
  ArticleInfo,
  ArticleListParams,
  ArticleListResultModel,
  ArticleAddReq,
  ArticleEditReq,
} from './model/articleModel';

enum Api {
  List = '/api/admin/v1/article/list',
  Create = '/api/admin/v1/article/add',
  Update = '/api/admin/v1/article/edit',
  Delete = '/api/admin/v1/article/del',
  Info = '/api/admin/v1/article/info',
}

export function getArticleList(params: ArticleListParams) {
  return defHttp.get<ArticleListResultModel>({
    url: Api.List,
    params,
  });
}

export function getArticleInfo(id: number) {
  return defHttp.get<ArticleInfo>({
    url: Api.Info,
    params: { id },
  });
}

export function createArticle(params: ArticleAddReq) {
  return defHttp.post<void>({
    url: Api.Create,
    params,
  });
}

export function updateArticle(params: ArticleEditReq) {
  return defHttp.put<void>({
    url: Api.Update,
    params,
  });
}

export function deleteArticle(id: number) {
  return defHttp.delete<void>({
    url: Api.Delete,
    params: { id },
  });
}
